import { _decorator, Component, Sprite, resources, SpriteAtlas, SpriteFrame, Texture2D } from 'cc';
import Language from "./Language";
import { LanguageSpriteObject } from './LanguageObject';

const { ccclass, property } = _decorator;

@ccclass("LanguageSprite")
export default class LanguageSprite extends Component {
    @property({ type: [LanguageSpriteObject] })
    private languageSpriteObject: LanguageSpriteObject[] = [];

    protected start(): void {
        this.changeLanguage(Language.Instance.type);
    }

    public changeLanguage(type: string): void {
        for (let i = 0; i < this.languageSpriteObject.length; i++) {
            if (this.languageSpriteObject[i].type === type) {
                let sprite = this.getComponent(Sprite);
                if (sprite) {
                    sprite.spriteFrame = this.languageSpriteObject[i].spriteFrame;
                }
                return;
            }
        }
    }
}
